﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using TTBusiness.DB_Linq;
namespace TTBusiness.ClassDB
{
    /// <summary>
    /// Create by ThiepND 23/3/2011
    /// </summary>
    public class clsBSManuFactory
    {
        TTMarketing_DBDataContext objDB = new TTMarketing_DBDataContext();
        public List<tblManuFactory> getAll()
        {
            try
            {
                var list = from a in objDB.tblManuFactories
                           select a;
                return list.ToList<tblManuFactory>();
            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<tblManuFactory> getStatus(bool status)
        {
            try
            {
                var list = from a in objDB.tblManuFactories
                           where a.Status.Equals(status)
                           select a;
                return list.ToList<tblManuFactory>();
            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<tblManuFactory> getVisible(bool visible)
        {
            try
            {
                var list = from a in objDB.tblManuFactories
                           where a.Visible.Equals(visible)
                           select a;
                return list.ToList<tblManuFactory>();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public tblManuFactory getById(int id)
        {
            try
            {
                var mf = objDB.tblManuFactories.SingleOrDefault(a => a.ID == id);
                return mf;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public tblManuFactory getByName(string name)
        {
            try
            {
                var mf = objDB.tblManuFactories.SingleOrDefault(a => a.Name == name);
                return mf;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void insert(tblManuFactory mf)
        {
            try
            {
                objDB.tblManuFactories.InsertOnSubmit(mf);
                objDB.SubmitChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        
        public void update(tblManuFactory mfc)
        {
            try
            {
                var mf = objDB.tblManuFactories.SingleOrDefault(a => a.ID == mfc.ID);
                if (mf != null)
                {
                    mf.Detail = mfc.Detail;
                    mf.ID = mfc.ID;
                    mf.Image = mfc.Image;
                    mf.Name = mfc.Name;
                    mf.Number = mfc.Number;
                    mf.Status = mfc.Status;
                    mf.Visible = mfc.Visible;
                    objDB.SubmitChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void update(int id,bool status)
        {
            try
            {
                var mf = objDB.tblManuFactories.SingleOrDefault(a => a.ID == id);
                if (mf != null)
                {
                    mf.Status = status;
                    objDB.SubmitChanges();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void delete(int id)
        {
            try
            {
                var mf = (from a in objDB.tblManuFactories
                          where a.ID == id
                          select a).SingleOrDefault();
                objDB.tblManuFactories.DeleteOnSubmit(mf);
                objDB.SubmitChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
